<html>
<head><meta charset="utf-8"><title>Reduced quality of IndexMut error message · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html">Reduced quality of IndexMut error message</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="160609650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609650">(Mar 12 2019 at 20:54)</a>:</h4>
<p><strong>Rust 2015</strong></p>
<div class="codehilite"><pre><span></span>error[E0594]: cannot assign to immutable indexed content
 --&gt; src/main.rs:8:5
  |
8 |     my_map[&quot;a&quot;] += 10;
  |     ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
  |
  = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `std::collections::HashMap&lt;&amp;str, i32&gt;`
</pre></div>


<p><strong>Rust 2018</strong></p>
<div class="codehilite"><pre><span></span>error[E0594]: cannot assign to data in a `&amp;` reference
 --&gt; src/main.rs:8:5
  |
8 |     my_map[&quot;a&quot;] += 10;
  |     ^^^^^^^^^^^^^^^^^ cannot assign
</pre></div>



<a name="160609686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609686">(Mar 12 2019 at 20:55)</a>:</h4>
<p>Is there an issue tracking restoring the earlier note, mentioning <code>IndexMut</code>?</p>



<a name="160609696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609696">(Mar 12 2019 at 20:55)</a>:</h4>
<p>It's a known issue.</p>



<a name="160609781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609781">(Mar 12 2019 at 20:56)</a>:</h4>
<p>Cool.</p>



<a name="160609790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609790">(Mar 12 2019 at 20:56)</a>:</h4>
<p>Hmm. It was "fixed"? <a href="https://github.com/rust-lang/rust/pull/53830" target="_blank" title="https://github.com/rust-lang/rust/pull/53830">https://github.com/rust-lang/rust/pull/53830</a></p>



<a name="160609825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609825">(Mar 12 2019 at 20:56)</a>:</h4>
<p>But is not fixed in 1.33</p>



<a name="160609881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609881">(Mar 12 2019 at 20:57)</a>:</h4>
<p>It looks like it was only fixed for mutable borrows</p>



<a name="160609981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609981">(Mar 12 2019 at 20:58)</a>:</h4>
<p>Ugh. Then it's the other issue</p>



<a name="160609985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160609985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160609985">(Mar 12 2019 at 20:58)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">collections</span>::<span class="n">HashMap</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">my_map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">HashMap</span>::<span class="o">&lt;&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="kt">i32</span><span class="o">&gt;</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">my_map</span><span class="p">[</span><span class="s">&quot;a&quot;</span><span class="p">]</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="160610000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160610000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160610000">(Mar 12 2019 at 20:58)</a>:</h4>
<p>cause it doesn't know to use <code>IndexMut</code> instead of <code>Index</code></p>



<a name="160610022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/Reduced%20quality%20of%20IndexMut%20error%20message/near/160610022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/Reduced.20quality.20of.20IndexMut.20error.20message.html#160610022">(Mar 12 2019 at 20:59)</a>:</h4>
<p>use / try, I guess</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>